{*
  Object Pascal simple window manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
}

unit WindowRoutines;

interface

uses
  Controls,
  Classes,
  Dialogs,
  ExtCtrls,
  Forms,
  Messages,
  SysUtils,
  Windows;

function ApplyFormSettings( Form: TForm; Style: AnsiString ): Boolean;
function WindowStateToString( wnstWindowState: TWindowState ): AnsiString;
function StringToWindowState( strnWindowState: AnsiString ): TWindowState;

implementation

function ApplyFormSettings( Form: TForm; Style: AnsiString ): Boolean;
begin
  try
    with Form do
    begin
      if AnsiCompareText( Style, 'Dialog' ) = 0 then
      begin
        BorderStyle := bsDialog;
        Position := poOwnerFormCenter;
        FormStyle := fsNormal;
        AutoScroll := False;
        Scaled := False;
        Font.Name := 'Tahoma';
        WindowState := wsNormal;
        VertScrollBar.Style := ssHotTrack;
        VertScrollBar.Smooth := True;
        VertScrollBar.Tracking := True;
      end;//if

      if AnsiCompareText( Style, 'MDIChild' ) = 0 then
      begin
        FormStyle := fsMDIChild;
        AutoScroll := True;
        Scaled := False;
        Font.Name := 'Tahoma';
        WindowState := wsMaximized;
        VertScrollBar.Style := ssHotTrack;
        VertScrollBar.Smooth := True;
        VertScrollBar.Tracking := True;
      end;//if
    end;//with
    Result := True;
  except
    Result := False;
  end;//try
end;

function WindowStateToString( wnstWindowState: TWindowState ): AnsiString;
begin

  case wnstWindowState of
    wsNormal: Result := 'wsNormal';
    wsMinimized: Result := 'wsMinimized';
    wsMaximized: Result := 'wsMaximized';
  end;//case

end;

function StringToWindowState( strnWindowState: AnsiString ): TWindowState;
begin

  Result := wsNormal;
  if AnsiCompareText( strnWindowState, 'wsMinimized' ) = 0 then Result := wsMinimized;
  if AnsiCompareText( strnWindowState, 'wsMaximized' ) = 0 then Result := wsMaximized;

end;

end.
